public class Solution1482 {
    public int minDays(int[] bloomDay, int m, int k) {
        int l=1,r=1000000000;
        int ans=-1;
        while (l<=r){
            int mid=(l+r)/2;
            int temp=0;
            int count=0;
            for (int i=0;i<bloomDay.length;i++){
                if (bloomDay[i]<=mid){
                    temp++;
                    if (temp==k){
                        temp=0;
                        count++;
                    }
                }else{
                    temp=0;
                }
            }
            if (count>=m){
                ans=mid;
                r=mid-1;
            }else{
                l=mid+1;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1482().minDays(new int[]{1,10,3,10,2},3,1));
    }
}
